package com.ruoyi.baidu.service.impl;


import com.ruoyi.baidu.service.AiExperimentRepository;
import com.ruoyi.system.api.domain.AiExperiment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AiExperimentService {

    @Autowired
    private AiExperimentRepository aiExperimentRepository;

    @Value("${spring.elasticsearch.page}")
    private int page;
    @Value("${spring.elasticsearch.size}")
    private int size;

    public Iterable<AiExperiment> findAll() {
        return aiExperimentRepository.findAll();
    }
    public void deleteAll() {
        aiExperimentRepository.deleteAll();
    }

    public AiExperiment save(AiExperiment aiExperiment) {
        return aiExperimentRepository.save(aiExperiment);
    }

    public List<AiExperiment> search(String keyword) {
        Pageable pageable = PageRequest.of(page, size);
        return aiExperimentRepository.findByExperimentNameOrExperimentType(keyword, keyword, pageable).getContent();
    }
}
